package xin.lhuo.we.server.utils;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;

/**
 * @author Lhuo
 * @date 2019/5/10 23:17
 */
public class InputStreamUtil {
    final static int BUFFER_SIZE = 4096;

    public static byte[] inputStreamToByte(InputStream inputStream) throws Exception {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

        byte[] data = new byte[BUFFER_SIZE];
        int count = -1;
        while ((count = inputStream.read(data, 0, BUFFER_SIZE)) != -1) {
            byteArrayOutputStream.write(data, 0, count);
        }
        data = null;
        return byteArrayOutputStream.toByteArray();
    }
}
